package com.paw.ruoyi.admin.common.utils;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.paw.ruoyi.admin.common.domain.Result;

/**
 * @author lvzihai
 * @date 2022/3/25
 **/
public class HttpResponseUtil {

  /**
   * 返回的json值
   *
   * @param response
   * @param result
   * @throws Exception
   */
  public static void writeReturnJson (HttpServletResponse response, Result result) throws Exception {
    PrintWriter writer = null;
    response.setCharacterEncoding("UTF-8");
    response.setContentType("text/html; charset=utf-8");
    try {
      writer = response.getWriter();
      writer.print(JSON.toJSONString(result));
    } catch (IOException e) {
    } finally {
      if (writer != null) {
        writer.close();
      }
    }
  }
}
